<?php
namespace Index\Controller;
//use Think\Controller;
use Index\Controller\CommonController;
class PeopleController extends CommonController {

    public function indexAction(    $uid=''){
//判断是哪个id进来
    if(!empty($uid)){
    	$id = $uid;
    }else{
    	$id= $_SESSION['uid'];
    }
    $Model = M();
    $userInfo = $Model->query("SELECT * FROM user where id='{$id}'");
    //判断是从哪个页面过来
    if (empty($userInfo)) {
    	$this->error('用户不存在',$_SERVER['HTTP_REFERER'],2);
    }
    //转成一维数组
    $userInfo= $userInfo[0];
    $this->assign('userInfo',$userInfo);



        /**
         * 回复
         */

//    var_dump($id);
    $sql = "select t1.content a,t2.content b,t2.title from answer t1 LEFT JOIN question t2 ON t1.qid=t2.id LEFT JOIN user t3 ON t1.uid=t3.id WHERE t3.id={$id}";
    $answer = $Model->query($sql);
//    var_dump($answer);
    $this->assign('answer',$answer);



    /**
     * 发问
     */
    $sql = "select * from question WHERE uid={$id}";
    $question = $Model->query($sql);
//    var_dump($question);
    $this->assign('question',$question);
        $this->display('index');
    }



}
